#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 50005;

int n, m;
struct Node {
  int w, s;
  bool operator<(const Node& o) const { return w + s < o.w + o.s; }
} a[N];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i].w >> a[i].s;
  sort(a + 1, a + n + 1);
  ll mx = -1e9, sum = 0;
  rep(i, 1, n) {
    mx = max(mx, sum - a[i].s);
    sum += a[i].w;
  }
  cout << mx;
  return 0;
}